package zabbix

import (
	"encoding/json"
	"errors"
)

func TemplateScreenCreateDate() (string,map[string]interface{}) {
	method := "templatescreen.create"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "name": "Graphs",
        "templateid": "10047",
        "hsize": 3,
        "vsize": 2,
        "screenitems": [
            {
                "resourcetype": 0,
                "resourceid": "410",
                "x": 0,
                "y": 0
            }
        ]
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func TemplateScreenDeleteDate() (string,map[string]interface{}) {
	method := "templatescreen.delete"
	var data map[string]interface{}
	jsonstr := []byte(`[
        "45",
        "46"
	]`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func TemplateScreenCopyDate() (string,map[string]interface{}) {
	method := "templatescreen.copy"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "screenIds": "25",
        "templateIds": "30085"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func TemplateScreenUpdateDate() (string,map[string]interface{}) {
	method := "templatescreen.update"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "screenid": "3",
        "name": "Performance graphs"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func TemplateScreenGetDate() (string,map[string]interface{}) {
	method := "templatescreen.get"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "output": "extend",
        "selectScreenItems": "extend",
        "templateids": "10001"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}


func TemplatescreenCreate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := TemplateScreenCreateDate()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func TemplatescreenDelete(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := TemplateScreenDeleteDate()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func TemplatescreenCopy(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := TemplateScreenCopyDate()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func TemplatescreenUpdate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := TemplateScreenUpdateDate()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func TemplatescreenGet(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := TemplateScreenGetDate()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}



